<?php 
namespace app\admin\model;

use think\Model;

class User extends Model
{
	public static function insert($data = array())
	{
		if (!empty($data))
		{
			$user = new User;
			foreach ($data as $key => $value) {
				$user->$key = $value;
			}
			if ($user->save())
			{
				return true;	
			} 
			else
			{
				return false;
			}
		}
		else 
		{
			return false;
		}
	}
	public static function getUserName()
	{
		$user = new User;
		$listName = $user->where('issearch = 0')->field(array('u_name','id'))->limit(1)->order('id desc')->select();
		foreach ($listName as $key => $value) {
			$id = $listName[$key]['id'];
			$user->save([
				'issearch' => 1
				], ['id' => $id]
				);
		}
		if ($listName)
		{
			return $listName;
		}
		else
		{
			return false;
		}
	}
	public static function backError($id)
	{
		$user = new User;

		if ($user->where('id', $id)->update(['issearch' => 2]))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	public static function updateUser($id, $data)
	{
		$user = new User;

		if ($user->where('id', $id)->update($data))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}